﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Controls;

namespace RollingText
{
    public class RollTextViewModel : TextBlock
    {
        public string FullText { get; set; }


        Timer timer;
        public RollTextViewModel()
        {
            timer = new Timer() { Interval = 500 };

            timer.Elapsed += RollingTXT;
            timer.Start();
        }
        private async Task Rolling()
        {
            var _txt = Text;
            while (true)
            {
                if (string.IsNullOrEmpty(Text))
                {
                    Text = _txt;
                }
                else
                {
                    Text = Text.Substring(1);
                }
                await Task.Delay(500);
            }
        }
        private void RollingTXT(object sender, ElapsedEventArgs e)
        {
            Dispatcher.Invoke(() =>
            {
                if (string.IsNullOrEmpty(Text))
                {
                    Text = _txt;
                }
                else
                {
                    Text = Text.Substring(1);
                }
            });
        }

        string _txt = string.Empty;

        public string Content
        {
            get { return _txt; }
            set { _txt = value; }
        }
    }
}
